#include <iostream>

int main(int argc, char const *argv[])
{
    /*
        the method of creating 2d array in C++

        1. DataType ArrayName[row][column];
        2. DataType ArrayName[row][column] = {
                                            {value1, value2},
                                            {value3, value4}
                                            }
        3. DataType ArrayName[row][column]  = {value1, value2, value3, value4};
        4. DataType ArrayName[][column] = {value1, value2, value3, value4};

    */

    // 1.
    const int R = 2;
    const int C = 2;
    int arr1[R][C];
    arr1[0][0] = 1;
    arr1[0][1] = 2;
    arr1[1][0] = 3;
    arr1[1][1] = 4;

    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            std::cout << arr1[i][j] << " " << (long)&arr1[i][j] << std::endl;
        }
    }

    std::cout << std::endl;

    // 2.
    int arr2[R][C] = {{1, 2}, {3, 4}};

    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            std::cout << arr2[i][j] << " " << (long)&arr2[i][j] << std::endl;
        }
    }

    std::cout << std::endl;

    // 3.
    // C = 4;
    // 当int R = 2; int C = 2; 没有带上const 关键字时，会是下面的情况
    // int arr3[R][C] = {1, 2, 3, 4}; // 在这儿使用变量代表数组长度会出问题，会被截断成 int arr3[2][C] = {1, 2};
    // int arr3[R][C] = {1, 2};
    // int arr3[2][C] = {1, 2, 3, 4}; // 截断成 int arr3[2][C] = {1, 2};
    // ----------------------
    // int arr3[R][2] = {1, 2, 3, 4}; // 正常 2 行 2 列 1 2 3 4
    int arr3[2][2] = {1, 2, 3, 4}; // 正常，2 行 2 列 1 2 3 4

    std::cout << sizeof(arr3) << std::endl;
    std::cout << sizeof(arr3[0][0]) << std::endl;
    std::cout << sizeof(arr3[0]) / sizeof(arr3[0][0]) << std::endl;

    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            // std::cout << "arr3[" << i << "][" << j << "] = " << arr3[i] << " " << (long) & arr3[i] << std::endl;
            std::cout << "arr3[" << i << "][" << j << "] = " << arr3[i][j] << " " << (long)&arr3[i][j] << std::endl;
        }
        std::cout << std::endl;
    }

    std::cout << std::endl;

    // 4.
    int arr4[R][C] = {1, 2, 3, 4};
    std::cout << sizeof(arr4) << std::endl;
    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            std::cout << "arr4[" << i << "][" << j << "] = " << arr4[i][j] << " " << (long)&arr4[i][j] << std::endl;
            // std::cout << arr4[i][j] << " ";
        }
    }

    std::cout << std::endl;

    return 0;
}
